/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;
import Database.Koneksi;
import Model.Kirim;
import Model.Member;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Dion
 */
public class pesananGudang { 
    public boolean kirim(String id){
        boolean hasil = false;
        int has = 0;
        //  String[] dataArray = email.split("/");

        Connection con = Koneksi.open();
        Statement st = null;
        ResultSet rs = null;
        try {
            //   String username = mem.getEmail();
            Statement stat = (Statement) con.createStatement();
            String sql = "update PEMESANAN set STATUS= 'Sudah Dikirim' where ID_PESAN='"+id+"'";
            //System.out.println("PAS"+password+"mail="+email);
            //  String query = " insert into BARANG values(?,?,?)";
            PreparedStatement statement = con.prepareStatement(sql);
            // statement.setString(1, dataArray[0]);
            //  statement.setString(2, dataArray[1]);
            
            has = statement.executeUpdate();
            con.commit();
        } catch (SQLException ex) {
            Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null, ex);
        }
        if (has > 0) {
            hasil = true;
        }
        return  hasil;
    }
    
    public List<Kirim>caribelumdikirim() throws SQLException{
        Kirim[] ret = null;
        Kirim pesan;
        List<Kirim> result=new ArrayList<Kirim>();
        String hasil1 = "error error";
        Connection con = Koneksi.open();
        String jdbcUrl = "jdbc:oracle:thin:@localhost:1521:XE";
        String name = "HR";
        String pass = "dion";
        String id = "";

        Statement stat = (Statement) con.createStatement();
        String query = "select * from PEMESANAN where STATUS='belumdikirim'";
        ResultSet hasil = stat.executeQuery(query);
        while (hasil.next()) {
        pesan = new Kirim();
        pesan.setIdBarang(hasil.getString(3));
        pesan.setIdPesan(hasil.getString(2));
        pesan.setTanggalPesan(hasil.getString(1));
        pesan.setJumlahPesan(hasil.getString(4));
        pesan.setStatus(hasil.getString(5));
        System.out.println("gggggggg="+hasil.getString(3));
        result.add(pesan);
        }
        for (int i = 0; i < result.size(); i++) {
            System.out.println(result.get(i).getIdBarang());   
        }   
        return result;
    }   
}